package leetcode142;
import domain.ListNode;

import java.util.HashMap;

public class Solution {
    public ListNode detectCycle(ListNode head) {
        //hash
        HashMap<ListNode,Boolean> map = new HashMap<>();
        while(head!=null){
            Boolean aBoolean = map.get(head);
            if(aBoolean==null||!aBoolean){
                map.put(head,Boolean.TRUE);
            }else{
                return head;
            }
            head = head.next;
        }
        return null;
    }
}